//
//  FCMileageAndOilWearView.m
//  OilWear
//
//  Created by jjkj on 17/7/10.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "FCMileageAndOilWearView.h"
#import "UIColor+Hex.h"
#import "UIButton+RoundedCorner.h"
#import "HomeCarModel.h"

@implementation FCMileageAndOilWearView

-(void)awakeFromNib {
    [super awakeFromNib];
    //[self setUpSwitchButtonAppreace:0];
    [self.mileage addRounedCornerWithRadius:10];
    [self.oilWear addRounedCornerWithRadius:10];
    
    //切半圆角
//    CGFloat radious = (CGFloat)self.onlineVehicleAmount.frame.size.height / 2;
//    
//    [self.onlineVehicleAmount changeButtonRadius:CGSizeMake(radious, radious) rectCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft ];
//    [self.offLineAmount changeButtonRadius:CGSizeMake(radious, radious) rectCorner:UIRectCornerTopRight|UIRectCornerBottomRight ];
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUp];
    }
    return  self;
}
- (void)setUp {
    [[NSBundle mainBundle] loadNibNamed:@"FCMileageAndOilWearView" owner:self options:nil];
        [self addSubview:self.view];
    
    self.view.frame = self.bounds;
    
}

- (IBAction)exchangeOnlineOrOfflineVehicle:(UIButton *)sender {
    NSInteger index = sender.tag - 300;
    
     //[self setUpSwitchButtonAppreace:index];
    
    if (self.exchangeVehicleBlock) {
        self.exchangeVehicleBlock(index);
    }
    NSLog(@"切换离线在线车辆");
}

- (void)setUpSwitchButtonAppreace:(NSInteger)index {
    
    if (0 == index) {
        
        self.onlineVehicleAmount.selected = YES;
        self.offLineAmount.selected = NO;
        
    }else {
        self.onlineVehicleAmount.selected = NO;
        self.offLineAmount.selected = YES;
    }
    
    [self setButtonAppreace:self.onlineVehicleAmount];
    [self setButtonAppreace:self.offLineAmount];
}

- (void)setButtonAppreace:(UIButton *)sender {
    
    if (YES == sender.selected) {
        //[sender setBackgroundColor:[UIColor colorWithHexString:@"0DA9D7"]];
        [sender setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [sender setTitleColor:[UIColor whiteColor] forState:(UIControlStateSelected)];
        [sender setBackgroundColor:[UIColor colorWithHexString:@"#009933"]];
        
        
    }else {
        // [sender setBackgroundColor:[UIColor whiteColor]];
        [sender setTitleColor:[UIColor colorWithHexString:@"#009933"] forState:(UIControlStateSelected )];
        [sender setTitleColor:[UIColor colorWithHexString:@"#009933"] forState:(UIControlStateNormal )];
        [sender setBackgroundColor:[UIColor colorWithHexString:@"#666666"]];
    }
}

//进入工作区详情页面
- (IBAction)enterWorkAreaDetailPage:(UIButton *)sender {
    NSLog(@"进入工作区详情页面");
    if (self.workAreaDetailBlock) {
        self.workAreaDetailBlock();
    }
}

- (void)setObjectWith:(HomeCarModel *)homeCarModel {
    
    [self.mileage setTitle:[NSString stringWithFormat:@"里程:%.2f公里",[homeCarModel.mile floatValue]] forState:(UIControlStateNormal)];
    [self.mileage setTitle:[NSString stringWithFormat:@"里程:%.2f公里",[homeCarModel.mile floatValue]] forState:(UIControlStateHighlighted)];
    
    [self.oilWear setTitle:[NSString stringWithFormat:@"加油量:%.2f升",[homeCarModel.iolLoss floatValue]] forState:(UIControlStateNormal)];
    [self.oilWear setTitle:[NSString stringWithFormat:@"加油量:%@升",homeCarModel.iolLoss] forState:(UIControlStateHighlighted)];
    
    [self.onlineVehicleAmount setTitle:[NSString stringWithFormat:@"在线车辆:%@辆",homeCarModel.nowCar] forState:(UIControlStateNormal)];
    [self.onlineVehicleAmount setTitle:[NSString stringWithFormat:@"在线车辆:%@辆",homeCarModel.nowCar] forState:(UIControlStateHighlighted)];
    
    [self.offLineAmount setTitle:[NSString stringWithFormat:@"离线车辆:%@辆",homeCarModel.leaveCar] forState:(UIControlStateNormal)];
    [self.offLineAmount setTitle:[NSString stringWithFormat:@"离线车辆:%@辆",homeCarModel.leaveCar] forState:(UIControlStateHighlighted)];

}
@end
